package test.persistent;

import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;

import com.cait.framework.data.filter.enOperaters;
import com.cait.framework.utils.Convert;
import com.cait.framework.utils.Guid;

import com.cait.workflowserver.definition.processdefinition.ProcessCategory;
import com.cait.workflowserver.definition.processdefinition.ProcessDef;
import com.cait.workflowserver.definition.processdefinition.ProcessXmlModel;
import com.cait.workflowserver.execution.execinstance.ProcessInstance;
import com.cait.workflowserver.execution.execinstance.enInstanceState;
import com.cait.workflowserver.persistent.DataProvider.oracledataprovider.OracleFlowCoreDataProvider;
import com.cait.workflowserver.runtime.Server;

import test.WorkFlowTest;

public class testPersistent extends WorkFlowTest {
	public testPersistent(String arg0)
	{
		super(arg0);
		
	}
	
	public void testInsertClass()
	{
//		Server.getInstance().start();
		
//		com.cait.framework.data.oracleClient.OraDataBase db=new com.cait.framework.data.oracleClient.OraDataBase();
//        String sql="select t5.*,(select t2.proc_xml_id " +
//        		" from wf_proc_xml_modle t2 " +
//        		" where t2.proc_id = t2.proc_id " +
//        		" and t2.proc_xml_create_date = t5.create_date) proc_xml_id " +
//        		" from(select t.proc_id," +
//        		"  max(t.proc_xml_create_date) create_date" +
//        		" from wf_proc_xml_modle t " +
//        		" group by t.proc_id) t5";
//        com.cait.framework.data.DataTable dt=db.executeQuery(sql);
        OracleFlowCoreDataProvider op=new OracleFlowCoreDataProvider();
//        for(int i=0;i<dt.size();i++)
//        {
//        	String s=Convert.toString(dt.getRows().get(i).get("proc_xml_id"));
//        	ProcessXmlModel pm=op.getProcessXmlModel(s);
//        	ProcessDef p=Server.getInstance().getProcDefineManager().getProcessDefByXml(pm.getXmlStore());
//        	System.out.println(p.getName());
//        	p.getProcHeader().setProcXmlModelId(s);
//        	p.getProcHeader().setCategoryId(Server.getInstance().getProcDefineManager().UnkownProcCatgory);
//        	op.insertProcessHeader(p.getProcHeader());
//        	
//        	
//        }
		
		
		
//		ProcessCategory pc=new ProcessCategory();
//		pc.setName("办公流程ere");
//		pc.setId("8a3c4f82-b188-4e82-95d4-63d14cd6aa63");
//		op.updateCategory(pc);
//		
//		 ProcessInstance pi=new ProcessInstance("dsd3-423423e334");
//		// pi.setId(Guid.getGuid());
//		 pi.setName("测试");
//		 pi.setState( enInstanceState.values()[4]);
//		 op.insertProcessInstance(pi);
//		 Server.getInstance().stop();
//		com.cait.workflowserver.definition.processdefinition.ProccessCollection ps=Server.getInstance().getWorkFlowRunner().getEnabledProcessDefs();
//		int a=1;
//		a=0;
 		//String sql="select * from wf_proc_def t where t.PROC_ID in (:ProcIDList)";
 		//String sql2="select * from wf_proc_def t where t.PROC_ID in ('56db1a84-9bd0-e2c1-2214-98967f999f19','c6a41f77-7f77-e620-b0af-356ab6859285')   ";
 		//String sql2="select * from wf_proc_def t where EXECUTE IMMEDIATE :ProcIDList ";
 		//com.cait.framework.data.oracleClient.OraDataBase oradb=new com.cait.framework.data.oracleClient.OraDataBase();
 	//	com.cait.framework.data.DBParameterCollection ps=oradb.createParams();
 		//String[] str={"t.PROC_ID in ('56db1a84-9bd0-e2c1-2214-98967f999f19'","c6a41f77-7f77-e620-b0af-356ab6859285)"};
    	//ps.add(":ProcIDList",str);
 	 	
 		// ps.add(":ProcIDList"," t.PROC_ID in ('56db1a84-9bd0-e2c1-2214-98967f999f19','c6a41f77-7f77-e620-b0af-356ab6859285') " );
 		//com.cait.framework.data.DataTable dt=oradb.executeQuery(sql2, ps);
 	//	System.out.println(dt.size() );
	  //System.out.println( op.getProcessInstanceListByCreator("8b103dd3-cef3-4250-b222-e9420c99e29f", null,new com.cait.framework.data.DevidePageParms(0,0)).size());
 	//	com.cait.workflowserver.definition.processdefinition.ProcessCategoryCollection pc=op.getChildProcessCategoryList(com.cait.workflowserver.definition.processdefinition.ProcessCategory.getVirRootId(), true);
	    // System.out.println(pc.size());
 		
// 		得到工作项返回
//.
		 com.cait.framework.data.filter.FilterDefinition filter=null;//new com.cait.framework.data.filter.FilterDefinition();
//		//设置过滤器条件
		//String mm="人工";
		
		String mm="人工";
		
//		try {
//			mm=new String(mm.getBytes("utf-8"),"utf-8");
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			//e.printStackTrace();
//		}
		System.out.println(mm);
	//	com.cait.framework.utils.Convert.isValidUtf8(b, aMaxCount)
		String m="<?xml version=\"1.0\" encoding=\"UTF-8\"?><FilterDefinition><FilterType>BOTH</FilterType><FilterConditionType>OR</FilterConditionType><PageParm><PageIndex>0</PageIndex><PageSize>20</PageSize></PageParm><ConditionItems><ConditionItem><FieldName>WORK_ITEM_NAME</FieldName><Operater>CONTAINS</Operater><FieldValue  DataType=\"STRING\">拟稿</FieldValue><IsConstraint>false</IsConstraint></ConditionItem><ConditionItem><FieldName>WORK_ITEM_OWNER_ID</FieldName><Operater>EQUALS</Operater><FieldValue  DataType=\"STRING\">8b103dd3-cef3-4250-b222-e9420c99e29f</FieldValue><IsConstraint>false</IsConstraint></ConditionItem><ConditionItem><FieldName>WORK_ITEM_STATE</FieldName><Operater>EQUALS</Operater><FieldValue  DataType=\"INTEGER\">2</FieldValue><IsConstraint>true</IsConstraint></ConditionItem></ConditionItems><OrderItems><OrderItem><FieldName>WORK_ITEM_CREATE_DATE</FieldName><OrderType>DESC</OrderType></OrderItem></OrderItems></FilterDefinition>";
		//String m="<?xml version=\"1.0\" encoding=\"UTF-8\"?><FilterDefinition><FilterType>BOTH</FilterType><FilterConditionType>AND</FilterConditionType><PageParm><PageIndex>0</PageIndex><PageSize>20</PageSize></PageParm><ConditionItems><ConditionItem><FieldName>WORK_ITEM_OWNER_ID</FieldName><Operater>EQUALS</Operater><FieldValue  DataType=\"STRING\">8b103dd3-cef3-4250-b222-e9420c99e29f</FieldValue></ConditionItem><ConditionItem><FieldName>WORK_ITEM_STATE</FieldName><Operater>EQUALS</Operater><FieldValue  DataType=\"INTEGER\">2</FieldValue></ConditionItem><ConditionItem><FieldName>WORK_ITEM_NAME</FieldName><Operater>CONTAINS</Operater><FieldValue  DataType=\"STRING\">人工</FieldValue></ConditionItem></ConditionItems><OrderItems></OrderItems></FilterDefinition>";
		
//		try {
//			m=new String(m.getBytes(),"utf-8");
//		} catch (UnsupportedEncodingException e) {
//			System.out.println("转换出错");
//		}
		
		filter=com.cait.workflowserver.interactiveface.webservice.transportmodel.FilterXmlDeserializer.Deserialize(m);
		 //filter.getConditionCollection().add("WORK_ITEM_OWNER_ID",enOperaters.EQUALS,"8b103dd3-cef3-4250-b222-e9420c99e29f");
		
	 
		 
		
			 
		//filter.getConditionCollection().add("WORK_ITEM_STATE",enOperaters.EQUALS,2);
		 
  
		
 
		
	//	filter.getDevidePageParms().pageIndex=0;
	//	filter.getDevidePageParms().pageSize=20;
		//System.out.println("分页:"+pageSize);
		//this.getFilter().setDevidePageParms(new DevidePageParms(pageIndex,pageSize));
		
		//filter.getConditionCollection().add("WORK_ITEM_NAME",enOperaters.CONTAINS,"人工活动1");
		
	//	try {
			//System.out.println("条件:"+this.getFilter().getConditionCollection().size());
			com.cait.workflowserver.execution.execinstance.WorkItemCollection wcc =op.queryWorkItems(filter);
			System.out.println("记录数:"+wcc.size());
//		}
//		catch (RemoteException e) {
//			return;
//		}
	}
}
